package com.gs.synedocket.presenter;

import com.google.gson.reflect.TypeToken;
import com.gs.synedocket.apiresult.ApiResultData;
import com.gs.synedocket.db.dto.ShortDto;
import com.gs.synedocket.model.ComboModel;
import com.gs.synedocket.model.SettingsModel;
import com.gs.synedocket.model.listener.OnResultListener;
import com.gs.synedocket.view.ITruckChangeView;

import java.util.List;

public class TruckChangePresenter extends BasePresenter<ITruckChangeView> {
    private ComboModel comboModel = new ComboModel();
    private SettingsModel settingsModel = new SettingsModel();

    public void changeTruck(final String truckId, String truckName) {
        getView().showLoading();
        settingsModel.changeTruck(truckId, new OnResultListener() {
            @Override
            public void onSuccess(Object apiResult) {
                if (getView() != null) {
                    getView().onUploadSuccess((ApiResultData<String>) apiResult, truckName,truckId);
                    getView().hideLoading();
                }
            }

            @Override
            public void onFails(Exception e) {
                if (getView() != null) {
                    getView().onUploadFail(e);
                    getView().hideLoading();
                }
            }
        }, new TypeToken<ApiResultData<String>>() {
        }.getType());
    }

    public void combo(String typeKey) {
        getView().showLoading();
        comboModel.comboLocal(typeKey,new OnResultListener() {
            @Override
            public void onSuccess(Object apiResult) {
                if (getView() != null) {
                    getView().onGetComListSuccess((ApiResultData<List<ShortDto>>) apiResult);
                    getView().hideLoading();
                }
            }

            @Override
            public void onFails(Exception e) {
                if (getView() != null) {
                    getView().onGetComListFails(e);
                    getView().hideLoading();
                }
            }
        }, new TypeToken<ApiResultData<List<ShortDto>>>() {
        }.getType());
    }
}
